fix: prevent prototype pollution in Chart.defaults path APIs#12268
Open
csworm-rudraksha wants to merge 1 commit into
Open
fix: prevent prototype pollution in Chart.defaults path APIs#12268csworm-rudraksha wants to merge 1 commit into
csworm-rudraksha wants to merge 1 commit into
Conversation
- Add isValidScopePath() to validate path segments - Reject '__proto__', 'prototype', and 'constructor' in scope paths - Fixes chartjs#12265 - prototype pollution gadget vulnerability This prevents prototype pollution via Chart.defaults.set(), get(), describe(), override(), and route() methods by validating path segments before walking them.
There was a problem hiding this comment.
Pull request overview
This PR hardens Chart.js’ path-based Chart.defaults APIs against prototype pollution by validating dotted scope strings before walking them in getScope().
Changes:
- Added scope-path segment validation to reject
__proto__,prototype, andconstructor - Updated
getScope()to throw a descriptive error when an invalid scope is provided
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+25
to
+27
| if (!isValidScopePath(key)) { | ||
| throw new Error(`Invalid defaults scope: ${key}`); | ||
| } |
Comment on lines
+11
to
+15
| function isValidScopePath(key) { | ||
| return !key.split('.').some((part) => ( | ||
| part === '__proto__' || part === 'prototype' || part === 'constructor' | ||
| )); | ||
| } |
Comment on lines
+25
to
+27
| if (!isValidScopePath(key)) { | ||
| throw new Error(`Invalid defaults scope: ${key}`); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a prototype pollution vulnerability in Chart.defaults path-based APIs reported in #12265.
Changes
isValidScopePath()function to validate path segments before walking themgetScope()to reject dangerous path segments (__proto__,prototype,constructor)Affected APIs
All path-based defaults APIs are now protected:
Chart.defaults.set(scope, values)Chart.defaults.get(scope)Chart.defaults.describe(scope, values)Chart.defaults.override(scope, values)Chart.defaults.route(scope, name, targetScope, targetName)Security Impact
Before: Attackers could pollute
Defaults.prototypevia paths like__proto__orconstructor.prototype, affecting all charts in the same realm.After: Dangerous path segments are rejected early with clear error messages, preventing prototype pollution.
Testing
Verified using the reproduction case from the security report. All attack vectors now throw
Invalid defaults scopeerrors:Closes #12265